<@sp.pagehead shiroUserHelper.getCurrentShiroUser().parentSources />
<div class="panel panel-inverse" data-sortable-id="form-validation-1">
    <div class="panel-heading">
        <h4 class="panel-title">菜单表单</h4>
    </div>
    <div class="panel-body">
        <form id="sourceAddForm" name="sourceAddForm" action="" method="post" class="form-horizontal form-bordered">
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">菜单名称</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="name" class="form-control" name="name" value="" placeholder="菜单名称 2-10位"
                           rangelength="2,10" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">菜单地址</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="sourceCode" class="form-control" name="sourceCode" value=""
                           placeholder="菜单地址 6-50位" rangelength="6,50" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">菜单排序</label>
                <div class="col-md-7 col-sm-7">
                    <input type="text" id="style" class="form-control" name="style" value="" placeholder="菜单排序,数字类型"
                           required/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">是否菜单</label>
                <div class="col-md-7 col-sm-7">
                    <select class="form-control" name="isMenu" id="isMenu" required>
                        <option value="">--请选择--</option>
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">是否日志</label>
                <div class="col-md-7 col-sm-7">
                    <select class="form-control" name="isLog" id="isLog" required>
                        <option value="">--请选择--</option>
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">菜单状态</label>
                <div class="col-md-7 col-sm-7">
                    <select class="form-control" name="status" id="status" required>
                        <option value="">--请选择--</option>
                        <option value="A">有效</option>
                        <option value="D">无效</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3">菜单描述</label>
                <div class="col-md-7 col-sm-7">
                    <textarea class="form-control" placeholder="请填写菜单描述.... 1-100位" rows="5" name="description"
                              rangelength="1,100"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">上级菜单</label>
                <div class="col-md-7 col-sm-7">
                    <select class="form-control" name="parentCode" id="parentCode">
                        <option value="">---请选择---</option>
                        <#if sourceTree?has_content && sourceTree?exists>
                        <#list sourceTree as st>
                        <option value="${st.id}">${st.name}</option>
                    </#list>
                </#if>
                </select>
            </div>
    </div>
    <div class="form-group">
        <label class="col-md-3 control-label">图标样式</label>
        <div class="col-md-7 col-sm-7">
            <input type="text" id="icon" class="form-control" name="icon" value="" placeholder="菜单图标"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-3 control-label"></label>
        <div class="col-md-7 col-sm-7">
            <button type="button" id="sourceAddSubmitButton" class="btn btn-sm btn-success">提交</button>
            <button type="button" class="btn btn-sm btn-default"
                    onclick="getData('${rc.contextPath}/source/query','${shiroUserHelper.getCurrentShiroUser().parentMenuSource.name}')">
                返回
            </button>
        </div>
    </div>
    </form>
    <script type="application/javascript">

        $(function () {
            $('#sourceAddSubmitButton').click(function () {
                $('#sourceAddForm').submit();
            })

            $('#sourceAddForm').validate({
                rules: {
                    style: {
                        isNumber: true
                    },
                    parentCode: {
                        isNumber: true
                    }
                },
                messages: {
                    style: {
                        isNumber: "请输入数字"
                    },
                    parentCode: {
                        isNumber: "请输入数字"
                    }
                },
                errorPlacement: function (error, element) {
                    error.appendTo(element.parent());
                },
                submitHandler: function () {
                    postDataByForm('${rc.contextPath}/source/add', '${shiroUserHelper.getCurrentShiroUser().parentMenuSource.name}', 'sourceAddForm');
                }
            })
        })
    </script>